package com.wanxi.fileandio.io;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class ReadWrite {
    public static void main(String[] args) {
        FileReader fileReader = null;
        FileWriter fileWriter = null;
        try {
            File file1 = new File("reader.txt");
            File file2 = new File("writer.txt");

            fileReader = new FileReader(file1);
            fileWriter = new FileWriter(file2);

            char[] cBuffer = new char[10];

            int len;

            while ((len = fileReader.read(cBuffer)) != -1) {
                fileWriter.write(cBuffer, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fileWriter != null)
                    fileWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                if (fileReader != null)
                    fileReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }
}
